<?php
/**
 * 短信设置
 * @author Administrator
 */
 
class sms extends admin{
    public function __construct(){
        parent::__construct();
        //array_walk_recursive($_GET,'safe_filter');
        //array_walk_recursive($_POST,'safe_filter');
    }
    
    
    public function index(){
        $sms = db()->getAll('select * from x_sms_tpl');
        $tpl = $this->Template();
        $tpl->assign('sms',$sms);
        $tpl->display();                
    }
    
    public function edit(){
        if(IS_AJAX){
            $id=(int)$_GET['id'];
            $data['label']=trim($_POST['label']);
            $data['content']=trim($_POST['content']);
            $affert_id=db()->update('x_sms_tpl',$data,'id='.$id);
            if($affert_id) $this->ajaxReturn(array('status'=>'y','info'=>'操作成功'));
            else $this->ajaxReturn(array('status'=>'n','info'=>'操作失败'));
        }else{
            $id=(int)$_GET['id'];
            $v=db()->getRow('select * from x_sms_tpl where id='.$id);
            $tpl=$this->Template();
            $tpl->assign('v',$v);
            $tpl->display();
        }
    }
    
    public function add(){
        if(IS_AJAX){
            $data['label']=trim($_POST['label']);
            $data['content']=trim($_POST['content']);
            $data['status']=1;
            $insert_id=db()->insert('x_sms_tpl',$data);            
            if($insert_id){
                $this->ajaxReturn(array('status'=>'y','info'=>'添加成功'));
            }else{
                $this->ajaxReturn(array('status'=>'n','info'=>'添加失败'));
            }
        }else{
            $tpl=$this->Template();
            $tpl->display(); 
        }
    }
    
    public function del(){
        if(IS_AJAX){
            $id=$_GET['id'];
            if($id<=0){
                $this->ajaxReturn(array('status'=>'n','info'=>'参数错误'));
            }
            $affert_rows=db()->delete('x_sms_tpl','id='.$id);
            if($affert_rows){
                $this->ajaxReturn(array('status'=>'y','info'=>'删除成功'));
            }else{
                $this->ajaxReturn(array('status'=>'n','info'=>'删除失败'));
            }
        }
    }
    
    
    
}